<?php 


class FlashSlider extends CWidget {

	public $width;
	
	public $height;
	
	public $htmlOptions;
	
	public $items = array();
	
	public function run() {
		self::registerScriptFile();
		$script = '
		    $(document).ready(function() {
           		$("#slider").flashSlider({
					pause:4000
				});
        	});
		';
		echo "<script>$script</script>";
		$html = '<div id="slider" style="height:'.$this->height.';width:'.$this->width.';" class="'.$this->htmlOptions['class'].'"><ul>';
		foreach ($this->items as $key=>$play){
			$html .= '<li>
						<a href="'.$play['link'].'" target="'.$play['target'].'">
							<img height="'.$this->height.'" width="'.$this->width.'" src="'.Yii::app()->request->baseUrl.$play['src'].'" alt="'.$play['title'].'" title="'.$play['title'].'"/>
						</a>
					</li>';
		}
		$html .= '</ul></div>';
		echo empty($this->items) ? '' : $html;
	}
	
	public static function registerScriptFile() {
		$jsUrl = Yii::app()->assetManager->publish(
			dirname(__FILE__).'/js/jquery.flashSlider-1.0.min.js'
		);
		echo '<script src="'.$jsUrl.'" type="text/javascript"></script>';
	}
}

?>